package com.bridgeintelligent.tag.webserver.dim.mgmt.service.export;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@AllArgsConstructor
@Api(tags = "标签excel导入")
@RestController
@RequestMapping("/api/dimExport")
public class ExportController {

    private IExportService iExportService;

    /**
     * 上传文件,批量添加基础标签
     *
     * @param excelFile
     * @return
     */
    @ApiOperation(value = "导入excel", notes = "标签excel导入")
    @PostMapping("/doExport")
    public DimRep upload(@RequestParam("excelFile") MultipartFile excelFile) {
        return iExportService.upload(excelFile);
    }

    /**
     * 上传文件,批量添加标签项
     *
     * @param excelItemFile
     * @return
     */
    @ApiOperation(value = "导入excel", notes = "标签excel导入")
    @PostMapping("/doItemExport")
    public DimRep doItemExport(@RequestParam("excelItemFile") MultipartFile excelItemFile) {
        return iExportService.itemUpload(excelItemFile);
    }

    /**
     * 上传批量标签文件和标签项文件
     *
     * @param excelItemFile
     * @return
     */
    @ApiOperation(value = "导入excel", notes = "标签excel导入")
    @PostMapping("/doDimExport")
    public DimRep doItemExport(@RequestParam("excelFile") MultipartFile excelFile, @RequestParam("excelItemFile") MultipartFile excelItemFile) {
        iExportService.upload(excelFile);
        iExportService.itemUpload(excelItemFile);
        return new DimRep(BaseCode.SUCCESS);
    }
}
